// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import iconfontcss from './fonts/iconfont.css';
import commoncss from './css/common.css';    // 共用样式
import Vue from 'vue';
import App from './App';
import router from './router';
import util from './js/util/util';
import "babel-polyfill";
import VueI18n from 'vue-i18n'
import MintUI from 'mint-ui'
//import vuePicturePreview from 'vue-picture-preview'
import 'mint-ui/lib/style.css'
import Vuex from 'vuex';

Vue.config.productionTip = false
Vue.use(VueI18n)
Vue.use(MintUI)
Vue.use(Vuex);
//Vue.use(vuePicturePreview)

var isTest=true;
// 如果在模块化构建系统中，请确保在开头调用了 Vue.use(Vuex)
//this.$store.state.token  子组件能通过 this.$store 访问到
const store = new Vuex.Store({
  state: {
    headings:'标题',
    isFooterShow:false,
    flag:0,
    type:0, 
    customer_appid: isTest ? 'wx9e64c093244fb42b' : 'wx059ae8af2befce8d', //微信ID
    worker_appid: isTest ? 'wxc623feee9451eb31': 'wx8d52e52502d04610',
    imgUrl:'',     //图片地址
    
    isIncome:'',
		priseName:'',
		priseRealname:'',
		priseAmount:'',
		receiveType:'',
		receiveStatus:'',
		orderNum:'',
		receiverName:'',
		receiverRealname:'',
		receiveTime:'',
		serviceCharge:'',
  },
   mutations: {
    token(state) {
      // 变更状态
    }
  },
})

const i18n = new VueI18n({
     locale: util.getLangByCookie('PLAY_LANG','zh'), // 通过 PLAY_LANG 属性来获取浏览器的语言,默认是'zh'
     messages: {
        'zh': require('./common/lang/zh'),
        'en': require('./common/lang/en')
    }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  store,
  i18n,
  router,
  template: '<App/>',
  components: { App }
})
//登录token
var token = localStorage.getItem("token");
//alert(token);
//处理登录~~~拦截器
router.beforeEach((to, from, next) => {
	  var matchedLength=to.matched.length;
	  if(matchedLength<=0){
	  	// util.pushRouter(router,'Error',{error:"404"}); //404错误页	
	  }else{
	  if(to.name!="注册"){ //判断该路由是否需要登录权限
	  	  if (token == 'null') {  // 通过vuex state获取当前的token是否存在
            util.pushRouter(router,'/kbc/h5/login'); //登录页  	
       }else{
        	  next(); 
        }
		  }else{
		  	  next();
		  }
	  }
});
